﻿using System.IO;
using System.Xml.Serialization;
using CommandRunner.Model;

namespace CommandRunner.Core
{
    public class ConfigurationManagerXML : ICommandRunnerConfigurationManager
    {
        public SimpleCommandList CommandList { get; private set; }

        public ConfigurationManagerXML(string xmlFilePath)
        {
            CommandList = Deserialize(xmlFilePath);
        }

        private SimpleCommandList Deserialize(string xmlFilePath)
        {
            SimpleCommandList commands;
            XmlSerializer serializer = new XmlSerializer(typeof(SimpleCommandList));
            using (TextReader reader = new StreamReader(xmlFilePath))
            {
                commands = (SimpleCommandList)serializer.Deserialize(reader);
            }
            return commands;
        }
    }
}
